package com.qf.team2.netdisc.common.exception.handler;

import com.qf.team2.netdisc.common.exception.BusinessException;
import com.qf.team2.netdisc.common.pojo.vo.RespResultVO;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 接管业务异常
 *
 * @author Simon_Wong
 * @date 2021/05/20
 * @since 2021/5/20 11:15
 */
@ControllerAdvice
public class BusinessExceptionHandler<T> {

    /**
     * 处理业务异常
     *
     * @param e 业务异常
     * @return {@link RespResultVO<T>}
     */
    @ResponseBody
    @ExceptionHandler(BusinessException.class)
    public RespResultVO<T> handleBusinessExceptions(BusinessException e) {
        //todo 记录日志
        RespResultVO<T> result = new RespResultVO<>();
        result.setStatus(RespResultVO.StatusCode.BUSINESS_EXCEPTION.getValue());
        result.setData(null);
        result.setMessage(e.getMessage());
        return result;
    }

}
